/**
 * Created by hcadmin on 16/4/7.
 */
define([
    "jquery",
    "IO",
    "bootbox"
], function ($, IO, bootbox) {
    var activity_mid=$("#activity_mid_hidden").val();
    $(function () {
        var companyName;
        IO.post("/shapan/api/groupNames",{activity_mid:activity_mid},function(d){
            companyName = d.data;
            if(companyName!=null){
                if(companyName[0].group_name!=null) {
                    $('.row2-input').val(companyName[0].group_name);
                    $('.row2-input').prop("readOnly", 'readOnly');
                }
                if(companyName[1].group_name!=null) {
                    $('.row3-input').val(companyName[1].group_name);
                    $('.row3-input').prop("readOnly", 'readOnly');
                }
                if(companyName[2].group_name!=null) {
                    $('.row4-input').val(companyName[2].group_name);
                    $('.row4-input').prop("readOnly", 'readOnly');
                }
                if(companyName[3].group_name!=null) {
                    $('.row5-input').val(companyName[3].group_name);
                    $('.row5-input').prop("readOnly", 'readOnly');
                }
                if(companyName[4].group_name!=null) {
                    $('.row6-input').val(companyName[4].group_name);
                    $('.row6-input').prop("readOnly", 'readOnly');
                }
                if(companyName[5].group_name!=null) {
                    $('.row7-input').val(companyName[5].group_name);
                    $('.row7-input').prop("readOnly", 'readOnly');
                }

                $("#btnSave").hide();
            }
        })

        $("#btnSave").click(function(){
            var compName1=$('.row2-input').val();
            var compName2=$('.row3-input').val();
            var compName3=$('.row4-input').val();
            var compName4=$('.row5-input').val();
            var compName5=$('.row6-input').val();
            var compName6=$('.row7-input').val();

            var params={};
            params.group_name1=compName1;
            params.group_name2=compName2;
            params.group_name3=compName3;
            params.group_name4=compName4;
            params.group_name5=compName5;
            params.group_name6=compName6;
            params.activity_mid=activity_mid;

            if(compName1!=""&&compName2!=""&&compName3!=""&&compName4!=""&&compName5!=""&&compName6!=""){

                IO.post("/shapan/api/newCompany",params,function(d){
                    if(d.code=="0"){
                        alert(d.msg);
                        location.href="/shapan/group/newcompany";
                    }
                })
            }
            else {
                alert("请输入6组信息");
            }
        });

    });

});